﻿#region Header

/*
    This file is part of nDoctor Light

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.Ldoc.Test
{
    using System;
    using System.Collections.Generic;
    using System.Threading;

    using NSubstitute;

    using NUnit.Framework;

    using Probel.Ldoc.Services.Dto;
    using Probel.Ldoc.Services.Services;
    using Probel.Ldoc.ViewModels.Helpers;
    using Probel.Ldoc.ViewModels.Pages;

    [TestFixture]
    public class TestSearchViewModel
    {
        #region Fields

        private readonly IErrorService ErrorService = Substitute.For<IErrorService>();

        #endregion Fields

        #region Methods

        [Test]
        [STAThread]
        public void SimpleSearch_Returns2Result_2ResultInResultField()
        {
            var result = GetPatientCard(2);
            var criterion = Guid.NewGuid().ToString();
            var service = Substitute.For<IPatientService>();
            var criterionFactory = Substitute.For<ICriterionFactory>();
            var viewmodel = new SearchViewModel(service, ErrorService, criterionFactory, false);

            criterionFactory.Build(Arg.Any<string>()).Returns(new SearchCriterion(string.Empty, true, true));
            service.GetPatients(criterionFactory.Build("")).Returns(result);

            Assert.AreEqual(0, viewmodel.SearchResult.Count);
            viewmodel.Criterion = criterion;
            viewmodel.SimpleSearchCommand.Execute(null);

            Assert.AreEqual(2, viewmodel.SearchResult.Count);
        }

        [SetUp]
        public void TestSetup()
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
        }

        private IEnumerable<PatientCardDto> GetPatientCard(int count)
        {
            var result = new List<PatientCardDto>();

            for (int i = 0; i < count; i++)
            {
                result.Add(new PatientCardDto()
                {

                });
            }
            return result;
        }

        #endregion Methods
    }
}